<html>
  <head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body class="tundra">
	<script type="text/javascript" src="../lib/dojo/dojo/dojo.js.uncompressed.js"
		djConfig="isDebug: true, debugAtAllCosts: true, parseOnLoad: true, usePlainJson: true"></script>
		
	<style>
		@import "../lib/dojo/dijit/themes/tundra/tundra.css"; /* required when dijit */	
		@import "../src/rforms/view/resources/rforms.css";
	</style>

	<script type="text/javascript">
		dojo.registerModulePath("rdfjson","../../../src/rdfjson");
		dojo.require("rdfjson.ajar.parser");
		dojo.require("dijit.form.SimpleTextarea");
		
		dojo.addOnLoad(function() {
		    var xhrArgs = {
		    		url: "testgraph.rdf",
					handleAs: "xml",
					load: function(xmldoc) {
						dijit.byId("source").set("value", rdfjson.ajar.XML2String(xmldoc));
						var graph = rdfjson.ajar.importRDFXML(xmldoc);
						dijit.byId("destination").set("value", dojo.toJson(graph.exportRDFJSON(), 1));
						var objectPartOfConstraint = {'type':'uri', 'value':'http://xmlns.com/foaf/0.1/Document'};
						var predicatePartOfConstraint = "http://www.w3.org/TR/rdf-schema/type";
						var directmatches = graph.find(null, predicatePartOfConstraint, objectPartOfConstraint);

						//Only rdfs:subClassOf and rdfs:subPropertyOf are supported
						var inferenceMatches = [];
						var subProperty = 'http://www.w3.org/2000/01/rdf-schema#subClassOf';
						var currentSubClass = {'type':'uri', 'value': 'http://xmlns.com/foaf/0.1/Document'};
						var foundSubClasses = graph.find(null, subProperty, currentSubClass); 
						if(foundSubClasses.length <= 0){
							subProperty = 'http://www.w3.org/2000/01/rdf-schema#subPropertyOf';
							foundSubClasses = graph.find(null, subProperty, currentSubClass);		
						}
						var i=0;
						while(i<foundSubClasses.length){ //Note: Does not detect loops...
							currentSubClass = foundSubClasses[i].getSubject();
							inferenceMatches.concat(graph.find(null, predicatePartOfConstraint, currentSubClass));
							//Add subClasses found from current SubClass
							foundSubClasses.concat(graph.find(null, subProperty, currentSubClass));
							i++;
						}
						var presentationString = 'Predicate-part of constraint: '+predicatePartOfConstraint+'\n';
						presentationString += 'Object-part of constraint: '+objectPartOfConstraint.value+'\n';
						presentationString += 'Nr of direct matches: '+ directmatches.length+'\n';
						presentationString += 'Nr of inference matches: '+ inferenceMatches.length+'\n';
						dijit.byId("Choices").set("value", presentationString, 1);
					}
		    };
			dojo.xhrGet(xhrArgs);
		});
	</script>
	<div style="width:33%;height:100%;float:left;">
		<h1>RDF/XML loaded from testgraph.rdf</h1>
		<div dojoType="dijit.form.SimpleTextarea" style="width: 99%;height:500px;" id="source"></div>
	</div>
	<div style="width:33%;height:100%;float:left;">
		<h1>Converted to RDF/JSON</h1>
		<div dojoType="dijit.form.SimpleTextarea" style="width:99%;height:500px;" id="destination"></div>
	</div>
	<div style="width:33%;height:100%;float:left;">
		<h1>Created choices</h1>
		<div dojoType="dijit.form.SimpleTextarea" style="width:99%;height:500px;" id="Choices"></div>
	</div>
  </body>
</html>